//
//  MCBankcardManageFooter.m
//  TLYL
//
//  Created by MC on 2017/7/11.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCBankcardManageFooter.h"
#define TIP  @"1.每一个账户只能绑定5张银行卡；\n\n2.一个账户绑定的多张银行卡的持卡人姓名必须一致；\n\n3.银行卡只支持添加，不支持变更和删除，请联系客服处理"
#define FONTTIP  11
@interface MCBankcardManageFooter ()

@property (nonatomic,strong)UIButton * btn_Add;
@property (nonatomic,strong)UILabel  * lab_tip;
@end
@implementation MCBankcardManageFooter
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}



-(void)createUI{
    
    self.backgroundColor=[UIColor clearColor];
    //添加银行卡
    _btn_Add=[[UIButton alloc]init];
    [self setFooter:_btn_Add];
    
    
    _lab_tip=[[UILabel alloc]init];
    _lab_tip.font=[UIFont systemFontOfSize:FONTTIP];
    [self addSubview:_lab_tip];
    _lab_tip.numberOfLines=0;
    _lab_tip.textColor=RGB(68, 68, 68);
    _lab_tip.alpha=128/255.0;
    _lab_tip.text=TIP;
    
    
    [self layOutConstraints];
    
}

/*
 * 点击 添加银行卡
 */
-(void)action_Add{
    
    if ([self.delegate respondsToSelector:@selector(goToAddBankcardViewController)]) {
        [self.delegate goToAddBankcardViewController];
    }
    
}

-(void)layOutConstraints{
    
    [_btn_Add mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(self.mas_top).offset(45);
        make.height.mas_equalTo(50);
        
    }];
    
    [_lab_tip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.bottom.equalTo(self.mas_bottom).offset(-10);
    }];
    
}

+(CGFloat)computeHeight:(int)info{
    
    NSString * content = TIP;
    CGSize textLabelSize    = [content boundingRectWithSize:CGSizeMake(G_SCREENWIDTH-20, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:FONTTIP]} context:nil].size;
    CGFloat min_H=50+45+textLabelSize.height +20;
    CGFloat H=(G_SCREENHEIGHT - (info*95+64));
    if (info==5) {
        return min_H-50;
    }
    if (H<min_H) {
        return min_H;
    }else{
        return H;
    }
    
}
-(void)setHiddenBtn{
    _btn_Add.hidden=YES;
}
-(void)setFooter:(UIButton *)btn{
    [_btn_Add setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btn_Add setTitle:@"添加银行卡" forState:UIControlStateNormal];
    _btn_Add.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    _btn_Add.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [_btn_Add setBackgroundImage:[UIImage imageNamed:@"Button_Determine"] forState:UIControlStateNormal];
//    [_btn_Add setImage:[UIImage imageNamed:@"Button_Determin_Right"] forState:UIControlStateNormal];
    //    [_btn_Save setBackgroundColor:RGB(80, 141, 207)];
    [self addSubview:_btn_Add];
    [_btn_Add addTarget:self action:@selector(action_Add) forControlEvents:UIControlEventTouchUpInside];
    _btn_Add.layer.cornerRadius=10.0;
    _btn_Add.clipsToBounds=YES;
    

}

@end




































